package panel.home;

import common.User;
import frame.Chat;
import other.HeadImage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Userinfo extends JPanel
{
    public Userinfo(User user,int f)
    {
        JLabel name = new JLabel("undefined");
        JLabel sign = new JLabel("undefined");
        //setVisible(true);
        setBounds(0,f*130,540,130);
        setOpaque(false);
        setLayout(null);

        // 头像
        HeadImage headImage = new HeadImage(user.username.isEmpty()?"undefined": user.username);
        headImage.setBounds(410, 0, 130);

        // 用户名
        if(!user.username.isEmpty()) name.setText(user.username);
        name.setOpaque(true);
        name.setHorizontalAlignment(SwingConstants.CENTER);
        name.setBackground(new Color(0, 0, 0, 20));
        name.setBounds(0, 0, 410, 60);
        name.setFont(new Font("宋体",Font.BOLD, 40));
        name.setForeground(Color.white);

        // 个性签名
        if(!user.sign.isEmpty()) sign.setText(user.sign);
        sign.setOpaque(true);
        sign.setHorizontalAlignment(SwingConstants.CENTER);
        sign.setVerticalAlignment(SwingConstants.CENTER);
        sign.setBackground(new Color(0, 0, 0, 20));
        sign.setBounds(0, 60, 410, 70);
        sign.setFont(new Font("宋体", Font.BOLD, 25));
        sign.setForeground(Color.lightGray);

        // 添加组件
        add(headImage);
        add(name);
        add(sign);


        // 监听点击
        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                Chat chat = new Chat(user);
            }
        });
    }
}
